import { nextTick, Ref, ref } from "@vue/composition-api";
import BetterScroll, { Options } from "@better-scroll/core";

export default function (refHost: Ref<HTMLElement | null>, bSOption?: Options): Ref<BetterScroll | null> {
    // betterScroll组件的响应式引用
    const bSInstance: Ref<BetterScroll | null> = ref(null);
    // DOM挂载完成后初始化BetterScroll
    nextTick(() => {
        if (refHost.value == null) {
            throw console.trace(
                "意料之外的情况：未捕捉到BetterScroll初始化的DOM元素"
            );
        }
        bSInstance.value = new BetterScroll(refHost.value, bSOption);
    });
    return bSInstance;
}
